using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
     class MRPDepartmentsService
    {
        ISession session;

        public MRPDepartmentsService(ISession session)
        {
            this.session = session;
        }
        public MRPDepartmentsService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpdepartments(MRPDepartments mrpdepartmentsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpdepartmentsX);
            tx.Commit();
        }

        public void UpdateMrpdepartments(MRPDepartments mrpdepartmentsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpdepartmentsX);
            tx.Commit();
        }

        public void DeleteMrpdepartments(MRPDepartments mrpdepartmentsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpdepartmentsX);
            tx.Commit();
        }

        public IList<MRPDepartments> GetAllMrpdepartments(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPDepartments");
            IList<MRPDepartments> list = query.List<MRPDepartments>();
            if (evict)
            {
                foreach (MRPDepartments s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPDepartments GetAllMrpdepartmentsByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPDepartments as c where c.Departmentid= :x");
            query.SetString("x", id);
            MRPDepartments s = (MRPDepartments)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPDepartments> GetMrpdepartmentsByQuery(IQuery query, Boolean evict)
        {
            IList<MRPDepartments> list = query.List<MRPDepartments>();
            if (evict)
            {
                foreach (MRPDepartments s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
